# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2025, The OpenROAD Authors

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("//bazel:python_wrap_cc.bzl", "python_wrap_cc")
load("//bazel:tcl_encode_or.bzl", "tcl_encode")
load("//bazel:tcl_wrap_cc.bzl", "tcl_wrap_cc")

package(
    default_visibility = ["//:__subpackages__"],
    features = ["layering_check"],
)

cc_library(
    name = "db_hdrs",
    hdrs = [
        "src/db/drObj/drAccessPattern.h",
        "src/db/drObj/drBlockObject.h",
        "src/db/drObj/drFig.h",
        "src/db/drObj/drMarker.h",
        "src/db/drObj/drNet.h",
        "src/db/drObj/drPin.h",
        "src/db/drObj/drRef.h",
        "src/db/drObj/drShape.h",
        "src/db/drObj/drVia.h",
        "src/db/gcObj/gcBlockObject.h",
        "src/db/gcObj/gcFig.h",
        "src/db/gcObj/gcNet.h",
        "src/db/gcObj/gcPin.h",
        "src/db/gcObj/gcShape.h",
        "src/db/grObj/grAccessPattern.h",
        "src/db/grObj/grBlockObject.h",
        "src/db/grObj/grFig.h",
        "src/db/grObj/grNet.h",
        "src/db/grObj/grNode.h",
        "src/db/grObj/grPin.h",
        "src/db/grObj/grRef.h",
        "src/db/grObj/grShape.h",
        "src/db/grObj/grVia.h",
        "src/db/infra/KDTree.hpp",
        "src/db/infra/frBox.h",
        "src/db/infra/frPoint.h",
        "src/db/infra/frSegStyle.h",
        "src/db/infra/frTime.h",
        "src/db/obj/frAccess.h",
        "src/db/obj/frBPin.h",
        "src/db/obj/frBTerm.h",
        "src/db/obj/frBlock.h",
        "src/db/obj/frBlockObject.h",
        "src/db/obj/frBlockage.h",
        "src/db/obj/frBoundary.h",
        "src/db/obj/frFig.h",
        "src/db/obj/frGCellPattern.h",
        "src/db/obj/frGuide.h",
        "src/db/obj/frInst.h",
        "src/db/obj/frInstBlockage.h",
        "src/db/obj/frInstTerm.h",
        "src/db/obj/frMPin.h",
        "src/db/obj/frMTerm.h",
        "src/db/obj/frMarker.h",
        "src/db/obj/frMaster.h",
        "src/db/obj/frNet.h",
        "src/db/obj/frNode.h",
        "src/db/obj/frPin.h",
        "src/db/obj/frRPin.h",
        "src/db/obj/frRef.h",
        "src/db/obj/frShape.h",
        "src/db/obj/frTerm.h",
        "src/db/obj/frTrackPattern.h",
        "src/db/obj/frVia.h",
        "src/db/taObj/taBlockObject.h",
        "src/db/taObj/taFig.h",
        "src/db/taObj/taPin.h",
        "src/db/taObj/taShape.h",
        "src/db/taObj/taVia.h",
        "src/db/tech/frConstraint.h",
        "src/db/tech/frLayer.h",
        "src/db/tech/frLookupTbl.h",
        "src/db/tech/frTechObject.h",
        "src/db/tech/frViaDef.h",
        "src/db/tech/frViaRuleGenerate.h",
    ],
    deps = ["@boost.polygon"],
)

cc_library(
    name = "drt",
    srcs = [
        "src/AbstractGraphicsFactory.h",
        "src/DesignCallBack.cpp",
        "src/DesignCallBack.h",
        "src/PACallBack.h",
        "src/TritonRoute.cpp",
        "src/db/drObj/drAccessPattern.cpp",
        "src/db/drObj/drNet.cpp",
        "src/db/drObj/drPin.cpp",
        "src/db/drObj/drShape.cpp",
        "src/db/drObj/drVia.cpp",
        "src/db/infra/KDTree.cpp",
        "src/db/infra/frTime.cpp",
        "src/db/obj/frAccess.cpp",
        "src/db/obj/frInst.cpp",
        "src/db/obj/frInstTerm.cpp",
        "src/db/obj/frMarker.cpp",
        "src/db/obj/frNet.cpp",
        "src/db/obj/frNode.cpp",
        "src/db/obj/frRPin.cpp",
        "src/db/obj/frShape.cpp",
        "src/db/obj/frVia.cpp",
        "src/db/taObj/taShape.cpp",
        "src/db/tech/frConstraint.cc",
        "src/db/tech/frLayer.cc",
        "src/distributed/PinAccessJobDescription.h",
        "src/distributed/RoutingCallBack.h",
        "src/distributed/RoutingJobDescription.h",
        "src/distributed/drUpdate.cpp",
        "src/distributed/drUpdate.h",
        "src/distributed/frArchive.cpp",
        "src/distributed/frArchive.h",
        "src/distributed/paUpdate.cpp",
        "src/distributed/paUpdate.h",
        "src/dr/AbstractDRGraphics.h",
        "src/dr/FlexDR.cpp",
        "src/dr/FlexDR.h",
        "src/dr/FlexDR_conn.cpp",
        "src/dr/FlexDR_conn.h",
        "src/dr/FlexDR_end.cpp",
        "src/dr/FlexDR_init.cpp",
        "src/dr/FlexDR_maze.cpp",
        "src/dr/FlexDR_rq.cpp",
        "src/dr/FlexGridGraph.cpp",
        "src/dr/FlexGridGraph.h",
        "src/dr/FlexGridGraph_maze.cpp",
        "src/dr/FlexMazeTypes.h",
        "src/dr/FlexWavefront.h",
        "src/frBaseTypes.cpp",
        "src/frBaseTypes.h",
        "src/frDesign.h",
        "src/frProfileTask.h",
        "src/frRTree.h",
        "src/frRegionQuery.cpp",
        "src/frRegionQuery.h",
        "src/gc/FlexGC.cpp",
        "src/gc/FlexGC.h",
        "src/gc/FlexGC_cut.cpp",
        "src/gc/FlexGC_eol.cpp",
        "src/gc/FlexGC_impl.h",
        "src/gc/FlexGC_inf.cpp",
        "src/gc/FlexGC_init.cpp",
        "src/gc/FlexGC_main.cpp",
        "src/gc/FlexGC_metspc.cpp",
        "src/gc/FlexGC_rq.cpp",
        "src/global.cpp",
        "src/global.h",
        "src/gr/FlexGR.cpp",
        "src/gr/FlexGR.h",
        "src/gr/FlexGRCMap.cpp",
        "src/gr/FlexGRCMap.h",
        "src/gr/FlexGRGridGraph.cpp",
        "src/gr/FlexGRGridGraph.h",
        "src/gr/FlexGRGridGraph_maze.cpp",
        "src/gr/FlexGRWavefront.h",
        "src/gr/FlexGR_end.cpp",
        "src/gr/FlexGR_init.cpp",
        "src/gr/FlexGR_maze.cpp",
        "src/gr/FlexGR_rq.cpp",
        "src/gr/FlexGR_topo.cpp",
        "src/io/GuideProcessor.cpp",
        "src/io/GuideProcessor.h",
        "src/io/io.cpp",
        "src/io/io.h",
        "src/io/io_parser_helper.cpp",
        "src/io/io_pin.cpp",
        "src/pa/AbstractPAGraphics.h",
        "src/pa/FlexPA.cpp",
        "src/pa/FlexPA.h",
        "src/pa/FlexPA_acc_pattern.cpp",
        "src/pa/FlexPA_acc_point.cpp",
        "src/pa/FlexPA_init.cpp",
        "src/pa/FlexPA_row_pattern.cpp",
        "src/pa/FlexPA_unique.cpp",
        "src/pa/FlexPA_unique.h",
        "src/rp/FlexRP.cpp",
        "src/rp/FlexRP.h",
        "src/rp/FlexRP_init.cpp",
        "src/rp/FlexRP_prep.cpp",
        "src/serialization.h",
        "src/ta/AbstractTAGraphics.h",
        "src/ta/FlexTA.cpp",
        "src/ta/FlexTA.h",
        "src/ta/FlexTA_assign.cpp",
        "src/ta/FlexTA_end.cpp",
        "src/ta/FlexTA_init.cpp",
        "src/ta/FlexTA_rq.cpp",
    ],
    hdrs = [
        "include/drt/TritonRoute.h",
    ],
    copts = [
        "-Isrc/drt/src",
        "-fopenmp",
    ],
    includes = [
        "include",
    ],
    deps = [
        ":db_hdrs",
        "//src/dst",
        "//src/odb",
        "//src/stt",
        "//src/utl",
        "@boost.asio",
        "@boost.bind",
        "@boost.container",
        "@boost.geometry",
        "@boost.graph",
        "@boost.icl",
        "@boost.io",
        "@boost.polygon",
        "@boost.serialization",
        "@openmp",
    ],
)

cc_library(
    name = "ui",
    srcs = [
        "include/drt/TritonRoute.h",
        "src/AbstractGraphicsFactory.h",
        "src/GraphicsFactory.cpp",
        "src/GraphicsFactory.h",
        "src/MakeTritonRoute.cpp",
        "src/distributed/drUpdate.h",
        "src/dr/AbstractDRGraphics.h",
        "src/dr/FlexDR.h",
        "src/dr/FlexDR_graphics.cpp",
        "src/dr/FlexDR_graphics.h",
        "src/dr/FlexGridGraph.h",
        "src/dr/FlexMazeTypes.h",
        "src/dr/FlexWavefront.h",
        "src/frBaseTypes.h",
        "src/frDesign.h",
        "src/frRegionQuery.h",
        "src/gc/FlexGC.h",
        "src/global.h",
        "src/pa/AbstractPAGraphics.h",
        "src/pa/FlexPA.h",
        "src/pa/FlexPA_graphics.cpp",
        "src/pa/FlexPA_graphics.h",
        "src/pa/FlexPA_unique.h",
        "src/ta/AbstractTAGraphics.h",
        "src/ta/FlexTA.h",
        "src/ta/FlexTA_graphics.cpp",
        "src/ta/FlexTA_graphics.h",
        ":swig",
        ":tcl",
    ],
    hdrs = [
        "include/drt/MakeTritonRoute.h",
    ],
    copts = [
        "-Isrc/drt/src",
        "-Wno-missing-braces",  # from TCL swigging
    ],
    includes = [
        "include",
    ],
    deps = [
        ":db_hdrs",
        ":drt",
        "//:ord",
        "//src/dst",
        "//src/gui",
        "//src/odb",
        "//src/utl",
        "@boost.asio",
        "@boost.container",
        "@boost.geometry",
        "@boost.polygon",
        "@boost.serialization",
        "@boost.stacktrace",
        "@tk_tcl//:tcl",
    ],
)

tcl_encode(
    name = "tcl",
    srcs = [
        "src/TritonRoute.tcl",
    ],
    char_array_name = "drt_tcl_inits",
    namespace = "drt",
)

tcl_wrap_cc(
    name = "swig",
    srcs = [
        "src/TritonRoute.i",
        "//:error_swig",
    ],
    module = "drt",
    namespace_prefix = "drt",
    root_swig_src = "src/TritonRoute.i",
    swig_includes = [
        "src/drt/src",
    ],
    deps = [
        "//src/odb:swig",
    ],
)

python_wrap_cc(
    name = "swig-py",
    srcs = [
        "include/drt/TritonRoute.h",
        "src/TritonRoute-py.i",
        "//:error_swig-py",
    ],
    module = "drt_py",
    root_swig_src = "src/TritonRoute-py.i",
    swig_includes = [
        "include",
    ],
    deps = [
        "//src/odb:swig-py",
    ],
)
